﻿<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-form
      :model="formData"
      :rules="rules"
      size="mini"
      labelPosition="right"
      labelWidth="80px"
      ref="form"
    >
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane
            class="l-tabs-container"
            :label="$t('主表信息')"
            name="tab0"
          >
            <el-row :gutter="0">
              <div class="l-rblock">
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Number')"
                  :span="12"
                >
                  <el-form-item
                    :label="$t('出库单号')"
                    prop="case_erp_outstorelog_f_Number"
                  >
                    <l-code
                      size="mini"
                      code="erp_outstorelog_number"
                      v-model="formData.case_erp_outstorelog_f_Number"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Theme')"
                  :span="12"
                >
                  <el-form-item
                    :label="$t('出库主题')"
                    prop="case_erp_outstorelog_f_Theme"
                  >
                    <el-input
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_Theme',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_outstorelog_f_Theme"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Date')"
                  :span="12"
                >
                  <el-form-item
                    :label="$t('出库日期')"
                    prop="case_erp_outstorelog_f_Date"
                  >
                    <l-date
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_Date',
                          isReadOnly
                        )
                      "
                      :readonly="false"
                      format="yyyy-MM-dd"
                      dateType="date"
                      :clearable="true"
                      v-model="formData.case_erp_outstorelog_f_Date"
                      :placeholder="$t('please select')"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Name')"
                  :span="12"
                >
                  <el-form-item
                    :label="$t('客户名称')"
                    prop="case_erp_outstorelog_f_Name"
                  >
                    <el-input
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_Name',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_outstorelog_f_Name"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Count')"
                  :span="12"
                >
                  <el-form-item
                    :label="$t('出库总量')"
                    prop="case_erp_outstorelog_f_Count"
                  >
                    <el-input
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_Count',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_outstorelog_f_Count"
                      :placeholder="$t('please enter')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Store')"
                  :span="12"
                >
                  <el-form-item
                    :label="$t('出库仓库')"
                    prop="case_erp_outstorelog_f_Store"
                  >
                    <l-layer-select
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_Store',
                          false || isReadOnly
                        )
                      "
                      :isPage="true"
                      :height="504"
                      :width="960"
                      :columns="[
                        {
                          label: '仓库编号',
                          prop: 'f_number',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '仓库名称',
                          prop: 'f_name',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '仓库地址',
                          prop: 'f_address',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '负责人',
                          prop: 'f_person',
                          valueKey: '',
                          minWidth: 100,
                          align: 'left',
                          hidden: false,
                          dataType: 'user',
                        },
                        {
                          label: '联系方式',
                          prop: 'f_phone',
                          valueKey: '',
                          minWidth: 100,
                          align: 'left',
                          hidden: false,
                        },
                      ]"
                      :options="case_erp_outstorelog_f_StoreOptions"
                      v-model="formData.case_erp_outstorelog_f_Store"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Person')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('出库人员')"
                    prop="case_erp_outstorelog_f_Person"
                  >
                    <l-user-select
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_Person',
                          isReadOnly
                        )
                      "
                      v-model="formData.case_erp_outstorelog_f_Person"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_SaleId')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('销售订单')"
                    prop="case_erp_outstorelog_f_SaleId"
                  >
                    <l-layer-select
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_SaleId',
                          false || isReadOnly
                        )
                      "
                      :isPage="true"
                      :height="504"
                      :width="960"
                      :columns="[
                        {
                          label: '销售单号',
                          prop: 'f_number',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '订单主题',
                          prop: 'f_theme',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '销售日期',
                          prop: 'f_saledate',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '客户名称',
                          prop: 'f_clientname',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                          dataType: 'dataSource',
                          dataCode: 'ERP_Customers',
                          valueKey: 'f_id',
                          labelKey: 'f_name',
                          isNotAutoWrap: true,
                        },
                        {
                          label: '联系人',
                          prop: 'f_clientperson',
                          valueKey: '',
                          minWidth: 100,
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '联系方式',
                          prop: 'f_clientway',
                          valueKey: '',
                          minWidth: 100,
                          align: 'left',
                          hidden: false,
                        },
                      ]"
                      :options="case_erp_outstorelog_f_SaleIdOptions"
                      v-model="formData.case_erp_outstorelog_f_SaleId"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_MaterialId')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('物料信息')"
                    prop="case_erp_outstorelog_f_MaterialId"
                  >
                    <l-layer-select
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_MaterialId',
                          false || isReadOnly
                        )
                      "
                      :isPage="true"
                      :height="504"
                      :width="960"
                      :columns="[
                        {
                          label: '物料编码',
                          prop: 'f_number',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '物料名称',
                          prop: 'f_name',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '规格型号',
                          prop: 'f_model',
                          valueKey: '',
                          minWidth: '150',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '单位',
                          prop: 'f_unit',
                          valueKey: '',
                          minWidth: '120',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '物料类别',
                          prop: 'f_type',
                          valueKey: '',
                          minWidth: '120',
                          align: 'left',
                          hidden: false,
                        },
                        {
                          label: '物料属性',
                          prop: 'f_property',
                          valueKey: '',
                          minWidth: '120',
                          align: 'left',
                          hidden: false,
                        },
                      ]"
                      :options="case_erp_outstorelog_f_MaterialIdOptions"
                      v-model="formData.case_erp_outstorelog_f_MaterialId"
                    />
                  </el-form-item>
                </el-col>
                <el-col
                  v-if="lr_formLookAuth('case_erp_outstorelog_f_Description')"
                  :span="24"
                >
                  <el-form-item
                    :label="$t('备注')"
                    prop="case_erp_outstorelog_f_Description"
                  >
                    <el-input
                      type="textarea"
                      :disabled="
                        !lr_formEditAuth(
                          'case_erp_outstorelog_f_Description',
                          isReadOnly
                        )
                      "
                      :rows="9"
                      v-model="formData.case_erp_outstorelog_f_Description"
                      :placeholder="$t('please enter')"
                    />
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>
<script>
const api = window.$api.erpcase.outstorelog;

export default {
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      moduleCode: "ERP_OutstoreLogs",
      activeName: "tab0",
      formData: {
        case_erp_outstorelog_f_Number: "", // 出库单号
        case_erp_outstorelog_f_Theme: "", // 出库主题
        case_erp_outstorelog_f_Date: "", // 出库日期
        case_erp_outstorelog_f_Name: "", // 客户名称
        case_erp_outstorelog_f_Count: "", // 出库总量
        case_erp_outstorelog_f_Store: "", // 出库仓库
        case_erp_outstorelog_f_Person: "", // 出库人员
        case_erp_outstorelog_f_SaleId: "", // 销售订单
        case_erp_outstorelog_f_MaterialId: "", // 物料信息
        case_erp_outstorelog_f_Description: "", // 备注
      },
      rules: {
        case_erp_outstorelog_f_Theme: [
          { required: true, message: "please enter出库主题" },
        ],
        case_erp_outstorelog_f_Date: [
          { required: true, message: "please select出库日期" },
        ],
        case_erp_outstorelog_f_Name: [
          { required: true, message: "please enter客户名称" },
        ],
        case_erp_outstorelog_f_Count: [
          { required: true, message: "please enter出库总量" },
          { pattern: /^\d+$|^\d*\.\d+$/g, message: "please enter数字" },
        ],
        case_erp_outstorelog_f_Store: [
          { required: true, message: "please enter出库仓库" },
        ],
        case_erp_outstorelog_f_Person: [
          { required: true, message: "please select出库人员" },
        ],
      },
    };
  },
  computed: {
    case_erp_outstorelog_f_SaleIdOptions() {
      const data = this.lr_DataSource("ERP_SaleList");
      return this.lr_DataSourceOptions(data, "f_id", "f_theme");
    },
    case_erp_outstorelog_f_MaterialIdOptions() {
      const data = this.lr_DataSource("ERP_Materials");
      return this.lr_DataSourceOptions(data, "f_id", "f_name");
    },
    case_erp_outstorelog_f_StoreOptions() {
      const data = this.lr_DataSource("ERP_WareHouses");
      return this.lr_DataSourceOptions(data, "f_id", "f_name");
    },
  },
  methods: {
    // Reset表单
    resetForm() {
      this.$formClear(this.$refs.form);
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }

      return true;
    },
    // 设置表单数据
    setForm(data) {
      this.$setFormData(this.formData, data, "case_erp_outstorelog");
    },
    // 获取表单数据
    getForm() {
      return this.$getFormData(this.formData, "case_erp_outstorelog");
    },

    async loadFormData({ keyValue /*,params,node*/ }) {
      //  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
      const data = await this.$awaitWraper(api.get(keyValue));
      if (data) {
        this.setForm(data);
        return true;
      } else {
        return false;
      }
    },

    async saveForm({ keyValue, isEdit /*,code,node*/ }) {
      // isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
      const postData = this.getForm();
      if (isEdit) {
        // Edit
        return await this.$awaitWraper(api.update(keyValue, postData));
      } else {
        // Add
        postData.f_Id = keyValue;

        return await this.$awaitWraper(api.add(postData));
      }
    },
  },
};
</script>